package com.yjhb.android.sbz.v2.mvp.presenter

import com.alibaba.fastjson.JSONObject
import com.yjhb.android.sbz.http.HttpObserver
import com.yjhb.android.sbz.http.HttpTool
import com.yjhb.android.sbz.v2.entity.VideoConfig
import com.yjhb.android.sbz.v2.mvp.V2ConventionPresenter
import com.yjhb.android.sbz.v2.mvp.view.V2VideoView


/**
 *  创建者 zx
 *  创建时间 2021/4/27 16:00
 */
class V2VideoPresenter(v: V2VideoView) : V2ConventionPresenter<V2VideoView>(v) {


    fun getVideoConfig() {
        model?.let {
            HttpTool.request(model.getVideoConfig(), object : HttpObserver<JSONObject>() {
                override fun onResult(data: JSONObject?) {
                    data?.let {
                        view?.onConf(it.getBoolean("show"),it.getIntValue("phase"),
                                it.getJSONArray("list").toJavaList(VideoConfig::class.java))
                    }
                }

                override fun onError(code: Int, msg: String?) {

                }
            })
        }
    }

    fun getVideoReward() {
        model?.let {
            HttpTool.request(model.getVideoReward(), object : HttpObserver<Int?>() {
                override fun onResult(data: Int?) {
                    data?.let {
                        view?.onReward(it)
                    }
                }

                override fun onError(code: Int, msg: String?) {

                }
            })
        }
    }

}